<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('人员树选择')" />
	<th:block th:include="include :: ztree-css" />
</head>
<style>
	body{height:auto;font-family: "Microsoft YaHei";}
	button{font-family: "SimSun","Helvetica Neue",Helvetica,Arial;}
</style>
<body class="hold-transition box box-main">
	<input id="treeId"   name="treeId"    type="hidden"/>
	<input id="treeName" name="treeName"  type="hidden"/>
	<div class="wrapper"><div class="treeShowHideButton" onclick="$.tree.toggleSearch();">
		<label id="btnShow" title="显示搜索" style="display:none;">︾</label>
		<label id="btnHide" title="隐藏搜索">︽</label>
	</div>
	<div class="treeSearchInput" id="search">
		<label for="keyword">关键字：</label><input type="text" class="empty" id="keyword" maxlength="50">
		<button class="btn" id="btn" onclick="$.tree.searchNode()"> 搜索 </button>
	</div>
	<div class="treeExpandCollapse">
		<a href="#" onclick="$.tree.expand()">展开</a> /
		<a href="#" onclick="$.tree.collapse()">折叠</a>
	</div>
	<div id="tree" class="ztree treeselect"></div>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: ztree-js" />
	<script th:inline="javascript">
	    var prefix = ctx + "basic/user"
		$(function() {
			var url = prefix + "/treeData";
			var options = {
		        url: url,
		        expandLevel: 2,
				check: { enable: true },
				onCheck : zOnCheck
		    };
			$.tree.init(options);
		});
		
		function zOnCheck(event, treeId, treeNode) {
			var treeType = treeNode.type;
			var treeId = treeNode.id;
			var treeId = treeId.substring(treeId.indexOf('_') + 1, treeId.length);
			var treeName = treeNode.name;
			if(treeType == 'user'){
				var userId = $("#treeId").val();
				var userName = $("#treeName").val();
				if(!userId.match(treeId)){
					if(userId == ''){
						userId = treeId;
						userName = treeName;
					}else{
						userId = userId + "," + treeId;
						userName = userName + "," + treeName;
					}
				}else{
					userId = userId.replace("," + treeId, "");
					userName = userName.replace("," + treeName, "");
				}
				$("#treeId").val(userId);
				$("#treeName").val(userName);
			}
		}
	</script>
</body>
</html>
